<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*"%> 
<%@ page import="java.util.*"%> 
<%@ page import="javax.naming.*"%> 
<%@ page import="javax.sql.*"%> 

 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.rhf.core.commons.logging.AppLog"%>
<%@page import="com.rhf.core.commons.logging.AppLogManager"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hello World 
<br />

<%


Connection conn = null;
String test = "";
String test2 = "";


try {
	
	
	System.out.print("toto");

	Context initContext = new InitialContext();    
	if ( initContext == null ) {
		test2 = "TTTTT";
		   throw new Exception("Uh oh -- no context!");
		}

	Context envContext  = (Context)initContext.lookup("java:/comp/env");            
	String envContextKey = "jdbc/postgres";
	DataSource ds = (DataSource)envContext.lookup(envContextKey);
	if (ds == null) {
		test2 += "UUUU";
		throw new Exception("Zut");
	}
	conn = ds.getConnection();
	
	 Statement stmt = null;  // Or PreparedStatement if needed
	  ResultSet rs = null;
	List<String> list = null;
	
	stmt = conn.createStatement();
    rs = stmt.executeQuery("SELECT * FROM toto");
    
    //test += stmt.toString();
    
    if (rs.next()) {
        list = new ArrayList<String>();
        test += rs.getString("test");
        list.add(rs.getString("test"));

        int i = 1;
        while (rs.next()) {
            list.add(rs.getString(1));
            test += rs.getString(1);

            i++;
        }
    }
 
    rs.close();
    rs = null;
    stmt.close();
    stmt = null;
    conn.close(); // Return to connection pool
    conn = null;  // Make sure we don't close it twice
	
} catch (Exception ex) {
	test = ex.getMessage();
    ex.printStackTrace();
} finally {
	if (conn != null) {
		conn.close();
		conn = null; 
	}
}

%>
<%=test%>
<br/>kldeee
<%= test2 %>

</body>
</html>